﻿namespace Pe.Petecos.Comercial.Cross.Document.Excel
{
    using System;
    using System.Collections.Generic;
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml.Spreadsheet;
    using DocumentFormat.OpenXml;

    /// <summary>
    /// Clase que representa el formato numérico aplicado a una celda excel
    /// </summary>
    /// <remarks>
    /// Creación:   GMD 20140304 <br />
    /// Modificación:       <br />
    /// </remarks>
    public class NumberFormat
    {
        /// <summary>
        /// Formatos numericos nativos de OPEN XML
        /// </summary>
        public NumberingFormats numberingFormats { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public uint HomeIndex { get; set; }
        /// <summary>
        /// Formato decimal de dos digitos
        /// </summary>
        public NumberingFormat TwoDecimalFormat { get; set; }
        /// <summary>
        /// Formato decimal de tres digitos
        /// </summary>
        public NumberingFormat ThreeDecimalFormat { get; set; }
        /// <summary>
        /// Formato de porcentaje
        /// </summary>
        public NumberingFormat PercentageFormat { get; set; }
        /// <summary>
        /// Formato numérico de dos digitos
        /// </summary>
        public NumberingFormat TwoNumberTextFormat { get; set; }
        /// <summary>
        /// Formato numérico de textos
        /// </summary>
        public NumberingFormat ForcedTextFormat { get; set; }
        /// <summary>
        /// Formato numérico de numeros enteros
        /// </summary>
        public NumberingFormat EnteroFormat { get; set; }
        /// <summary>
        /// Formato decimal
        /// </summary>
        public NumberingFormat DecimalFormat { get; set; }

        /// <summary>
        /// Constructor por Defecto de implementación de la clase.
        /// </summary>
        public NumberFormat()
        {
            this.numberingFormats = new NumberingFormats();
            this.HomeIndex = 164;
            this.EnteroFormat = CreateFormat("#,##0");
            this.TwoDecimalFormat = CreateFormat("#,##0.00");//CreateTwoDecimalFormat();
            this.ThreeDecimalFormat = CreateFormat("#,##0.000");
            this.DecimalFormat = CreateFormat("#,##0.00##");
            this.PercentageFormat = CreateFormat("#,##0.00%");//CreateFormatPercent();
            this.TwoNumberTextFormat = CreateFormat("00");//CreateTwoNumberTextFormat();
            this.ForcedTextFormat = CreateFormat("@"); //CreateForcedText();
        }
        /// <summary>
        /// Permite crear el formato a aplicar
        /// </summary>
        /// <param name="format">Cadena con el formato</param>
        /// <returns>Formato numérico de celda</returns>
        private NumberingFormat CreateFormat(string format)
        {
            NumberingFormat numberingFormat = new NumberingFormat();
            numberingFormat.NumberFormatId = UInt32Value.FromUInt32(HomeIndex++);
            numberingFormat.FormatCode = StringValue.FromString(format);
            this.numberingFormats.Append(numberingFormat);
            return numberingFormat;
        }       

    }


}
